(function(){if(window.BlogBFileDialog)return;window.BlogBFileDialogUniqueID=[];window.BlogBFileDialog=function(e){this.dialogName="AttachmentsDialog";this.agent=false;this.uploadFileUrl=e.upload_path;this.id=!!e["id"]?e["id"]:this.getID();this.controlID=e["id"];this.enabled=true;this.controller=!!e.controller?e.controller:null;this.fileInput=e.fileInput;e.hAttachEvents=BX.delegate(this.InitAgent,this);this.msg=e.msg;this.dropAutoUpload=e.dropAutoUpload;this.CID=e.CID;this.multiple=!!e.multiple;e.caller=this;e.classes={uploaderParent:"file-uploader",uploader:"file-fileUploader",tpl_simple:"file-simple",tpl_extended:"file-extended",selector:"file-selector",selector_active:"file-selector-active"};e.doc_prefix="wd-doc";e.placeholder=BX.findChild(this.controller,{className:"file-placeholder-tbody"},true);this.doc_prefix=e.doc_prefix;this.values=e["values"]||[];if(!!BX.FileUploadAgent){this.agent=new BX.FileUploadAgent(e);BX.addCustomEvent(this,"ShowUploadedFile",BX.delegate(this.ShowUploadedFile,this));BX.addCustomEvent(this,"StopUpload",this.StopUpload.bind(this));BX.onCustomEvent(BX(this.controller.parentNode),"BFileDLoadFormControllerInit",[this])}else{BX.debug("/bitrix/components/bitrix/main.file.input/templates/drag_n_drop/script.js: BX.FileUploadAgent is not defined."+" You need to load /bitrix/js/main/file_upload_agent.js")}};window.BlogBFileDialog.prototype.getID=function(){return""+(new Date).getTime()};window.BlogBFileDialog.prototype.InitAgent=function(e){if(this.controller){e.placeholder=BX.findChild(this.controller,{className:"file-placeholder-tbody"},true)}};window.BlogBFileDialog.prototype.ShowUploadedFile=function(e){this.agent=e;var i=e.uploadResult;if(i&&i.element_id>0){var t=this.CreateFileRow(i);if(!!e.inputName&&e.inputName.length>0){var o=BX.create("INPUT",{props:{id:"file-doc"+i.element_id,type:"hidden",name:e.inputName+(this.multiple?"[]":""),value:i.element_id}});t.appendChild(o)}this.values.push(t);e._clearPlace();if(this.controller&&this.controller.parentNode){const e=(this.controller.closest("form")||this.controller.parentNode).querySelector("#upload-cid");if(e){e.value=this.CID}BX.onCustomEvent(this.controller.parentNode,"OnFileUploadSuccess",[i,this])}}else{var l=i&&i["error"]?i["error"]:this.msg.upload_error;e.ShowUploadError(l);if(this.controller&&this.controller.parentNode)BX.onCustomEvent(this.controller.parentNode,"OnFileUploadFail")}};window.BlogBFileDialog.prototype.CreateFileRow=function(e){var t=e;var o="file";if(!!t.element_content_type&&t.element_content_type.indexOf("image/")==0&&!!t.element_image&&t.element_image.length>0&&!!t.element_thumbnail&&t.element_thumbnail.length>0){o="image"}var l=BX.clone(BX("file-"+o+"-template"));BX.template(l,BX.delegate((function(e){this.tplFileRow(e,t)}),this));if(o=="image"){var n=null;for(i=0;i<l.children.length;i++){n=l.children[i];if(n.nodeType==1)break}n.setAttribute("id",this.doc_prefix+e.element_id);var a=BX.findChild(n,{className:"feed-add-post-del-but"},true);BX.bind(a,"click",BX.delegate((function(){var e=a;var i=e.parentNode;this.agent.StopUpload(i);BX.cleanNode(i,true)}),this));this.agent.AddNodeToPlaceholder(n);l=n}else{l.setAttribute("id",this.doc_prefix+e.element_id);this.agent.AddRowToPlaceholder(l);l=this.agent.placeholder.querySelector("#"+this.doc_prefix+e.element_id)}return l};window.BlogBFileDialog.prototype.GetUploadDialog=function(e){return new BlogBFileDialogUploader(this,e)};window.BlogBFileDialog.prototype.tplFileRow=function(e,i){for(id in e){if(!e.hasOwnProperty(id))continue;var t=e[id];if(id=="image"&&!!i.element_image&&i.element_image.length>0&&!!i.element_thumbnail&&i.element_thumbnail.length>0){t.setAttribute("src",i.element_image);t.setAttribute("rel",i.element_thumbnail)}else{if(!!i["element_"+id])t.innerHTML=i["element_"+id]}}};window.BlogBFileDialog.prototype._addUrlParam=function(e,i){if(!e)return null;if(e.indexOf(i)==-1)e+=(e.indexOf("?")==-1?"?":"&")+i;return e};window.BlogBFileDialog.prototype.LoadDialogs=function(e){if(!!this.agent)this.agent.LoadDialogs(e);else{var i=e;setTimeout(BX.delegate((function(){this.LoadDialogs(i)}),this),100)}};window.BlogBFileDialog.prototype.StopUpload=function(e,i){this.agent=e;var t=0;var o=new RegExp(this.doc_prefix+"(\\d+)");if(o.test(i.id)){var l=i.id.match(o);t=l[1]}if(this.controller&&this.controller.parentNode){BX.onCustomEvent(this.controller.parentNode,"OnFileUploadRemove",[t,this])}var n={fileID:t,sessid:BX.bitrix_sessid(),cid:this.CID,controlID:this.controlID,mfi_mode:"delete"};BX.ajax({method:"POST",dataType:"html",url:this.uploadFileUrl,processData:false,data:BX.ajax.prepareData(n),onsuccess:function(){}})};window.BlogBFileDialogDispatcher=function(e){this.id=this.getID();this.controller=e;BX.loadScript("/bitrix/js/main/core/core_dd.js",BX.delegate((function(){if(BX.type.isElementNode(this.controller)&&this.controller.parentNode&&this.controller.parentNode.parentNode){var e=this.controller.parentNode.parentNode;this.dropbox=new BX.DD.dropFiles(e);if(this.dropbox&&this.dropbox.supported()&&BX.ajax.FormData.isSupported()){this.hExpandUploader=BX.proxy(this.ExpandUploader,this);BX.addCustomEvent(this.dropbox,"dragEnter",this.hExpandUploader);BX.addCustomEvent(e,"UnbindDndDispatcher",BX.delegate(this.Unbind,this))}}}),this))};window.BlogBFileDialogDispatcher.prototype.getID=function(){return""+(new Date).getTime()};window.BlogBFileDialogDispatcher.prototype.ExpandUploader=function(){BX.onCustomEvent(BX(this.controller.parentNode),"BFileDLoadFormController",["show"])};window.BlogBFileDialogDispatcher.prototype.Unbind=function(){BX.removeCustomEvent(this.dropbox,"dragEnter",this.hExpandUploader)};window.BlogBFileDialogUploader=function(e,i){this.WDUploaded=false;this.WDUploadInProgress=false;this.documentExists=false;this.fileDropped=false;this.caller=e;this.agent=i;this.parentID=this.agent.id;this.id=this.caller.getID();this.msg=e.msg;this.dropAutoUpload=e.dropAutoUpload;this.uploadFileUrl=e.uploadFileUrl;this.CID=e.CID;this.controlID=e.controlID;this.CreateElements();this.fileInput=!!i.fileInput?i.fileInput:BX.type.isDomNode(i.fileInputID)?i.fileInputID:BX(e.fileInput);if(BX.type.isDomNode(this.fileInput)){this.fileInput.name="mfi_files[]"}this.fileList=this.__form;BX.loadScript("/bitrix/js/main/core/core_dd.js",BX.delegate((function(){var e=new BX.DD.dropFiles;if(e&&e.supported()&&BX.ajax.FormData.isSupported()){this.dropbox=e}this.agent.BindUploadEvents(this)}),this))};window.BlogBFileDialogUploader.prototype.CreateElements=function(){var e;do{e=Math.floor(Math.random()*99999)}while(BX("iframe-"+e));var i="iframe-"+this.id;var t=BX.create("IFRAME",{props:{name:i,id:i},style:{display:"none"}});document.body.appendChild(t);this.iframeUpload=t;var o=BX.create("FORM",{props:{id:"form-"+e,method:"POST",action:this.uploadFileUrl,enctype:"multipart/form-data",encoding:"multipart/form-data",target:i},style:{display:"none"},children:[BX.create("INPUT",{props:{type:"hidden",name:"sessid",value:BX.bitrix_sessid()}}),BX.create("INPUT",{props:{type:"hidden",name:"uniqueID",value:e}}),BX.create("INPUT",{props:{type:"hidden",name:"cid",value:this.CID}}),BX.create("INPUT",{props:{type:"hidden",name:"controlID",value:!!this.controlID?this.controlID:""}}),BX.create("INPUT",{props:{type:"hidden",name:"mfi_mode",value:"upload"}})]});document.body.appendChild(o);this.__form=o;window["FILE_UPLOADER_CALLBACK_"+e]=BX.proxy(this.Callback,this)};window.BlogBFileDialogUploader.prototype.GetUploadFileName=function(){var e="";if(this.fileInput&&this.fileInput.value.length>0){var e=this.fileInput.value;if(e.indexOf("\\")>-1)e=e.substr(e.lastIndexOf("\\")+1)}else{var i=this.fileList;if(i.file)e=i.file.fileName||i.file.name}return e};window.BlogBFileDialogUploader.prototype.Callback=function(e,i){if(BX.type.isArray(e)){e.forEach(function(e){var i={success:true,storage:"bfile",element_id:e.fileID,element_name:e.fileName,element_size:e.fileSize,element_url:e.fileURL,element_content_type:e.content_type||e.fileContentType,element_image:e.img_thumb_src||e.fileSrc,element_thumbnail:e.img_source_src||e.fileSrc};if(!!i.element_image)i.element_image=i.element_image.replace(/\/([^\/]+)$/,(function(e,i){return"/"+BX.util.urlencode(i)}));if(!!i.element_thumbnail)i.element_thumbnail=i.element_thumbnail.replace(/\/([^\/]+)$/,(function(e,i){return"/"+BX.util.urlencode(i)}));if(e["error"]||e["status"]==="error"){i["error"]=e["error"]||e["message"]}BX.onCustomEvent(this,"uploadFinish",[i])}.bind(this))}else{BX.onCustomEvent(this,"uploadFinish",[{success:false,messages:BX.type.isNotEmptyString(e)?e:this.msg.upload_error}])}window["FILE_UPLOADER_CALLBACK_"+i]=BX.DoNothing;BX.cleanNode(BX("iframe-"+i),true);BX.cleanNode(BX("form-"+i),true);this.agent.uploadDialog=null};window.BlogBFileDialogUploader.prototype.UploadResponse=function(e,i){this.WDUploadInProgress=false;BX.unbind(window,"beforeunload",BX.proxy(this.UploadLeave,this));if(!i||i.length<=0){this.onError()}};window.BlogBFileDialogUploader.prototype.UploadResponseIframe=function(e,i){this.WDUploadInProgress=false;BX.unbind(window,"beforeunload",BX.proxy(this.UploadLeave,this))};window.BlogBFileDialogUploader.prototype.UploadLeave=function(e){var e=e||window.event;var i="";if(this.WDUploadInProgress)i=this.msg.UploadInterrupt;else if(!this.WDUploaded&&this.fileInput&&this.fileInput.value.length>0)i=this.msg.UploadNotDone;if(i!=""){if(e)e.returnValue=i;return i}return};window.BlogBFileDialogUploader.prototype.UpdateListFiles=function(e){if(this&&e){if(e.length<1)return;var i=this.fileList;i.file=e[0];this.WDUploadInProgress=true;this.fileDropped=true;this.CallSubmit()}};window.BlogBFileDialogUploader.prototype.GetInputData=function(e){var i=[];var t={};i=i.concat(BX.findChildren(e,{tag:"input"},true),BX.findChildren(e,{tag:"textarea"},true),BX.findChildren(e,{tag:"select"},true));for(var o=0;o<i.length;o++){var l=i[o];if(!l||l.disabled||l.name.length<1)continue;switch(l.type.toLowerCase()){case"text":case"textarea":case"password":case"hidden":case"select-one":t[l.name]=l.value;break;case"radio":if(l.checked)t[l.name]=l.value;break;case"checkbox":t[l.name]=l.checked?"Y":"N";break;case"select-multiple":var n=l.options.length;if(n>0)t[l.name]=new Array;for(j=0;j<n;j++)if(l.options[j].selected)t[l.name].push(l.options[j].value);break;default:break}}return t};window.BlogBFileDialogUploader.prototype.SetFileInput=function(e){if(!!this.__form.mfi_save)return;if(this.fileInput&&this.fileInput!=e)BX.remove(this.fileInput);this.__form.appendChild(e);this.fileInput=e};window.BlogBFileDialogUploader.prototype.CallSubmit=function(){if(!!this.__form.mfi_save)return;BX.onCustomEvent(this,"uploadStart",[this]);BX.bind(window,"beforeunload",BX.proxy(this.UploadLeave,this));BX.bind(this.iframeUpload,"load",BX.delegate(this.UploadResponseIframe,this));if(this.dropbox){this.onProgress(.15);if(this.fileInput&&this.fileInput.files.length>0){var e=this.fileList;e.file=this.fileInput.files[0]}var t=this.GetInputData(this.__form);this.fileNodes=[this.fileList];for(i in this.fileNodes){if(this.fileNodes[i].file){var o=new BX.ajax.FormData;for(item in this.fileNodes[i].data){o.append(item,this.fileNodes[i].data[item])}if(!!Object&&!!Object.keys){var l=Object.keys(t);for(var n in l){var a=l[n];var r=t[a];o.append(a,r)}}else{for(item in t){o.append(item,t[item])}}o.append("mfi_files[]",this.fileNodes[i].file);o.send(this.uploadFileUrl,BX.delegate((function(e){this.UploadResponse(null,e)}),this),BX.delegate(this.onProgress,this))}}}else{this.onProgress(.15);this.WDUploadInProgress=true;var s=this.__form.id;BX.submit(this.__form,"mfi_save","Y")}};window.BlogBFileDialogUploader.prototype.onProgress=function(e){if(isNaN(e))return;BX.onCustomEvent(this,"progress",[e])};window.BlogBFileDialogUploader.prototype.onError=function(){BX.onCustomEvent(this,"uploadFinish",[{success:false,messages:this.msg.upload_error}])};top.BlogBFileDialog=window.BlogBFileDialog;top.BlogBFileDialogUploader=window.BlogBFileDialogUploader;top.BlogBFileDialogDispatcher=window.BlogBFileDialogDispatcher;window.MFIDD=function(e){BX.loadCSS("/bitrix/components/bitrix/main.file.input/templates/drag_n_drop/style.css");var i=e["status"]==="show"?"show":e["status"]==="hide"?"hide":"switch";if(i=="switch")i=e["controller"].style.display!="none"?"hide":"show";var t=function(i){if(i=="show"){BX.fx.show(e["controller"],"fade",{time:.2});if(e["switcher"]&&e["switcher"].style.display!="none")BX.fx.hide(e["switcher"],"fade",{time:.1});if(!!window["BfileUnbindDispatcher"+e["uid"]])window["BfileUnbindDispatcher"+e["uid"]]()}else if(e["controller"].style.display!=="none"){BX.fx.hide(e["controller"],"fade",{time:.2})}};if(!e["controller"].loaded){e["controller"].loaded=true;var o=new BX.DD.dropFiles,l=o&&o.supported()&&BX.ajax.FormData.isSupported()?"extended":"simple";top["BfileFD"+e["uid"]]=window["BfileFD"+e["uid"]]=new BlogBFileDialog({mode:l,CID:e["CID"],id:e["id"],upload_path:e["upload_path"],multiple:e["multiple"],controller:e["controller"],inputName:e["inputName"],fileInput:"file-fileUploader-"+e["uid"],fileInputName:"mfi_files[]",values:BX.findChildren(BX("file-selectdialog-"+e["uid"]),{className:"file-inline-file"},true),msg:{loading:BX.message("loading"),file_exists:BX.message("file_exists"),upload_error:BX.message("upload_error"),access_denied:BX.message("access_denied")}});t(i);window["BfileFD"+e["uid"]].LoadDialogs("DropInterface");BX.onCustomEvent("BFileDSelectFileDialogLoaded",[window["BfileFD"+e["uid"]]])}else t(i)};window.BlogBFileJustDialog=function(e){this.dialogName="AttachmentsDialog";this.agent=false;this.id=!!e["id"]?e["id"]:this.getID();this.controlID=e["id"];this.enabled=true;this.uploadFileUrl=e.upload_path;this.controller=!!e.controller?e.controller:null;this.CID=e.CID;e.caller=this;e.doc_prefix="wd-doc";e._mkFileInput=BX.DoNothing;e.mode="extended";e.classes={tpl_simple:"file-simple",tpl_extended:"file-extended"};this.doc_prefix=e.doc_prefix;if(!!BX.FileUploadAgent){this.agent=new BX.FileUploadAgent(e);BX.addCustomEvent(this,"StopUpload",BX.delegate(this.StopUpload,this));BX.onCustomEvent(BX(this.controller.parentNode),"BFileDLoadFormControllerInit",[this])}else{BX.debug("/bitrix/components/bitrix/main.file.input/templates/drag_n_drop/script.js: BX.FileUploadAgent is not defined."+" You need to load /bitrix/js/main/file_upload_agent.js")}};window.BlogBFileJustDialog.prototype.StopUpload=function(e,i){this.agent=e;id=false;mID=i.id.match(new RegExp(this.doc_prefix+"(\\d+)"));if(!!mID){id=mID[1]}if(this.controller&&this.controller.parentNode)BX.onCustomEvent(this.controller.parentNode,"OnFileUploadRemove",[id,this]);var t={fileID:id,sessid:BX.bitrix_sessid(),cid:this.CID,controlID:this.controlID,mfi_mode:"delete"};BX.ajax.post(this.uploadFileUrl,t)};window.MFIS=function(e){if(!e["controller"].loaded){e["controller"].loaded=true;top["BfileFD"+e["uid"]]=window["BfileFD"+e["uid"]]=new BlogBFileJustDialog({CID:e["CID"],id:e["id"],upload_path:e["upload_path"],controller:e["controller"],values:BX.findChildren(BX("file-selectdialog-"+e["uid"]),{className:"file-inline-file"},true)});BX.fx.show(e["controller"],"fade",{time:.2});BX.onCustomEvent("BFileDSelectFileDialogLoaded",[window["BfileFD"+e["uid"]]])}}})(window);
//# sourceMappingURL=script.map.js